package com.si.controller.manage;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

import com.si.entity.OperationLog;
import com.si.service.BlogrollService;
import com.si.service.OperationLogService;
import com.si.util.IpAddressUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.si.entity.Bottom;
import com.si.service.BottomService;

/**
 * 底部信息设置
 * @author 10605
 *
 */
@Controller
@RequestMapping("bottom/manage")
public class BottomManageController {

	@Autowired
	private BottomService bottomService;
	@Autowired
	private OperationLogService operationLogService;
	/**
	 * 进入到修改页面
	 * @param modelmap
	 * @return
	 */
	@RequestMapping(value="initUpdate")
	public String initUpdate(
			ModelMap modelmap,
			@ModelAttribute("message") String message){
		List<Bottom> bottomList=bottomService.getAll();
		if(bottomList.size()>0){
			Bottom bottom=(Bottom)bottomList.get(0);
			modelmap.put("bottom", bottom);
		}
		modelmap.put("message", message);
		return "managePage/bottom/update";
	}
	
	/**
	 * 
	 * @param modelmap
	 * @param redirectAttributes
	 * @param aboutUsId
	 * @param cnContent
	 * @param enContent
	 * @param rTWContent
	 * @return
	 */
	@RequestMapping(value="update")
	public String update(
			ModelMap modelmap,
			HttpServletRequest request,
			RedirectAttributes redirectAttributes,
			@RequestParam(value = "bottomId", required = true) Integer bottomId,
			@RequestParam(value = "address", required = true) String address,
			@RequestParam(value = "banquan", required = true) String banquan,
			@RequestParam(value = "support", required = true) String support,
			@RequestParam(value = "systemName", required = true) String systemName,
			@RequestParam(value = "tel", required = true) String tel){
		Bottom bottom=(Bottom)bottomService.getObjectById(bottomId);
		bottom.setAddress(address);
		bottom.setBanquan(banquan);
		bottom.setSupport(support);
		bottom.setSystemName(systemName);
		bottom.setTel(tel);
		bottomService.saveOrUpdate(bottom);
		OperationLog operationLog = new OperationLog();
		operationLog.setMiaoshu("执行成功！");
		operationLog.setOperationdetails("添加/修改底部信息\""+bottom.getSystemName()+"\"");
		operationLog.setOperationtime(new Date().toString());
		operationLog.setSensitive("添加底部信息");
		String ip = IpAddressUtil.getIpAddress(request);
		operationLog.setIpadderse(ip);
		String sysUser = (String) request.getSession().getAttribute("session_sysUser_name");
		operationLog.setUsername(sysUser);
		operationLogService.save(operationLog);
		redirectAttributes.addFlashAttribute("message", "\"底部信息\"保存成功");
		return "redirect:/bottom/manage/initUpdate.html";
	}
}
